/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sk.itat.wicket;

import java.util.ArrayList;
import java.util.Arrays;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

/**
 *
 * @author opteron1441
 */
public final class ReservationRoomPage extends BasePage {

    private Uzivatel person;
    private int rok;
    private int den;
    private int mesiac;

    public ReservationRoomPage() {
        super();

        add(new HeaderPanel("mainNavigation", "Reservation Hotel Room"));
    }

    public ReservationRoomPage(Uzivatel params) {
        super();
        person = params;


        RoomRegistration regRoom = new RoomRegistration();
        CompoundPropertyModel roomModel = new CompoundPropertyModel(regRoom);

        Form roomForm = new RoomForm("roomReg", roomModel);

        DropDownChoice hotels = new DropDownChoice("hotel", Arrays.asList(new String[]
        {"Double Tree, Hlavná 1, Košice", "Maraton Hotel, Terasa 54, Košice", "Carlton, Nabrežná 23, Bratislava","Hotel Slovan, Slovenská 54, Bratislava",
         "Hotel republika, Námestie osloboditeľov,Bardejiv","Hotel Poprad, Duklianská 45, Poprad","Hotel Tatry, Tatranská Lomnica 20, Tatranská Lomnica"}));
        hotels.setRequired(true);
        DropDownChoice roomSize = new DropDownChoice("velkostIzby", Arrays.asList(new String[]{"1", "2", "3", "4"}));
        roomSize.setRequired(true);

        TextField dlzkaPobytu = new TextField("dlzkaRezervacie");
        dlzkaPobytu.setRequired(true);

        ArrayList<String> mesiacList = new ArrayList<String>();
        for (int i = 1; i < 13; i++) {
            mesiacList.add(String.valueOf(i));
        }
        DropDownChoice mesiacLbl = new DropDownChoice("mesiac", new PropertyModel(this, "mesiac"), mesiacList);
        mesiacLbl.setRequired(true);

        ArrayList<String> denList = new ArrayList<String>();
        for (int i = 1; i < 32; i++) {
            denList.add(String.valueOf(i));
        }
        DropDownChoice denLbl = new DropDownChoice("den", new PropertyModel(this, "den"), denList);
        denLbl.setRequired(true);

        DropDownChoice rokLbl = new DropDownChoice("rok", new PropertyModel(this, "rok"), Arrays.asList(new String[]{"2011", "2012"}));
        rokLbl.setRequired(true);



        roomForm.add(hotels);
        roomForm.add(roomSize);
        roomForm.add(dlzkaPobytu);
        roomForm.add(rokLbl);
        roomForm.add(mesiacLbl);
        roomForm.add(denLbl);



        add(new HeaderPanel("mainNavigation", "Reservation hotel Room"));
        add(roomForm);
        add(new FeedbackPanel("errors"));
    }

    public class RoomForm extends Form {

        public RoomForm(String id, IModel model) {
            super(id, model);

        }

        @Override
        protected void onSubmit() {
            RoomRegistration regRoom = (RoomRegistration) getModelObject();
            regRoom.setDatum(den+" . "+mesiac+" . "+rok);
            person.getZoznamRezervacii().add(regRoom);
            System.out.println(regRoom);

            setResponsePage(new WelcomePage(person));

            //setResponsePage(WelcomePage.class, params_uziv);
        }
    }

    public int getDen() {
        return den;
    }

    public void setDen(int den) {
        this.den = den;
    }

    public int getMesiac() {
        return mesiac;
    }

    public void setMesiac(int mesiac) {
        this.mesiac = mesiac;
    }

    public int getRok() {
        return rok;
    }

    public void setRok(int rok) {
        this.rok = rok;
    }
}
